/*********************************************************************
*                                                                    *
*                SEGGER Microcontroller GmbH                         *
*        Solutions for real time microcontroller applications        *
*                                                                    *
**********************************************************************
*                                                                    *
* C-file generated by:                                               *
*                                                                    *
*        GUI_Builder for emWin version 6.16                          *
*        Compiled Nov 13 2020, 12:50:00                              *
*        (c) 2019 Segger Microcontroller GmbH                        *
*                                                                    *
**********************************************************************
*                                                                    *
*        Internet: www.segger.com  Support: support@segger.com       *
*                                                                    *
**********************************************************************
*/

// USER START (Optionally insert additional includes)
// USER END

#include "DIALOG.h"
//#include "bsp_usart.h"
//#include "bsp_led.h" 
/*********************************************************************
*
*       Defines
*
**********************************************************************
*/
#define ID_FRAMEWIN_0 (GUI_ID_USER + 0x00)
#define ID_EDIT_0 (GUI_ID_USER + 0x02)
#define ID_BUTTON_0 (GUI_ID_USER + 0x03)
#define ID_CHECKBOX_0 (GUI_ID_USER + 0x04)
#define ID_BUTTON_1 (GUI_ID_USER + 0x05)
#define ID_PROGBAR_0 (GUI_ID_USER + 0x06)


// USER START (Optionally insert additional defines)
// USER END

/*********************************************************************
*
*       Static data
*
**********************************************************************
*/
char EDIT_Buff[50];
extern GUI_CONST_STORAGE GUI_FONT GUI_FontmyFort;
extern GUI_CONST_STORAGE GUI_BITMAP bmset;
/*********************************************************************
*
*       _aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
  { FRAMEWIN_CreateIndirect, "MainWindow", ID_FRAMEWIN_0, 0, 0, 240, 320, 0, 0x64, FRAMEWIN_CF_MOVEABLE },
  { EDIT_CreateIndirect, "Edit", ID_EDIT_0, 106, 52, 80, 20, 0, 0x64, 0 },
  { BUTTON_CreateIndirect, "Button_LED", ID_BUTTON_0, 14, 46, 50, 30, 0, 0x0, 0 },
  { CHECKBOX_CreateIndirect, "Checkbox", ID_CHECKBOX_0, 108, 104, 82, 20, 0, 0x0, 0 },
  { BUTTON_CreateIndirect, "", ID_BUTTON_1, 15, 97, 50, 50, 0, 0x0, 0 },
  { PROGBAR_CreateIndirect, "Progbar", ID_PROGBAR_0, 23, 225, 166, 20, 0, 0x0, 0 },
  // USER START (Optionally insert additional widgets)
  // USER END
};

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/

// USER START (Optionally insert additional static code)
// USER END

/*********************************************************************
*
*       _cbDialog
*/
static int dragStarted = 0;
static int startX = 0;
static int startY = 0;
static void _cbDialog(WM_MESSAGE * pMsg) {
  WM_HWIN hItem;
  int     NCode;
  int     Id;
  // USER START (Optionally insert additional variables)
  // USER END

  switch (pMsg->MsgId) {
  case WM_INIT_DIALOG: //初始化消息
    //
    // 初始化 'MainWindow'
    hItem = pMsg->hWin;
    FRAMEWIN_SetFont(hItem, GUI_FONT_13_1);
    FRAMEWIN_SetTitleHeight(hItem, 30);
    FRAMEWIN_SetTextColor(hItem, GUI_MAKE_COLOR(0x000000FF));
    FRAMEWIN_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
    
  
	GUI_UC_SetEncodeUTF8();
	FRAMEWIN_SetFont(hItem, &GUI_FontmyFort);
	FRAMEWIN_SetText(hItem, "梁梁梁窗窗窗");
    //
    // 初始化 'Edit'
    hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0);
    EDIT_SetText(hItem, "");
    //
    // 初始化 'Checkbox'
    hItem = WM_GetDialogItem(pMsg->hWin, ID_CHECKBOX_0);
    CHECKBOX_SetText(hItem, "Check");
    // USER START (可选择插入其他代码以进行进一步的小部件初始化)
    // USER END
	//
	// 初始化 BUTTON1
	hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
	BUTTON_SetBkColor(hItem, BUTTON_CI_UNPRESSED, GUI_WHITE);
	BUTTON_SetBitmap(hItem,BUTTON_BI_UNPRESSED,&bmset);
    break;
  case WM_NOTIFY_PARENT://子窗口发生变化的消息
    Id    = WM_GetId(pMsg->hWinSrc); //获取控件ID
    NCode = pMsg->Data.v;
    switch(Id) {
    case ID_EDIT_0: // Notifications sent by 'Edit'
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED://点击事件
        // USER START (插入用于对通知消息作出反应的代码（可选）)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED://释放事件
        // USER START 
        // USER END
        break;
      case WM_NOTIFICATION_VALUE_CHANGED:
        // USER START 
        // USER END
        break;
      // USER START 
      // USER END
      }
      break;
    case ID_BUTTON_0: // “按钮”发送的通知
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:
        // USER START 
		//LED1_TOGGLE;
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START 
        // USER END
        break;
      // USER START 
      // USER END
      }
      break;
    case ID_CHECKBOX_0: // 'Checkbox'发送的通知
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:
        // USER START
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START 
        // USER END
        break;
      case WM_NOTIFICATION_VALUE_CHANGED:
        // USER START
        // USER END
        break;
      // USER START 
      // USER END
      }
      break;
    case ID_BUTTON_1: //Button发送的通知
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:
        // USER START
	  hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0);
	  EDIT_GetText(hItem,EDIT_Buff,20);
	 // printf("%s\n",EDIT_Buff);
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START 
        // USER END
        break;
      // USER START 
      // USER END
      }
      break;
    // USER START 
    // USER END
    }
    break;
  // USER START 
  // USER END

  
 
  default:
    WM_DefaultProc(pMsg);
    break;
  }
}

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       CreateMainWindow
*/
WM_HWIN CreateMainWindow(void);
WM_HWIN CreateMainWindow(void) {
  WM_HWIN hWin;

  hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
  FRAMEWIN_SetMoveable(hWin, 1);
  WM_SetDesktopColor(GUI_WHITE);
  FRAMEWIN_AddCloseButton(hWin, FRAMEWIN_BUTTON_RIGHT, 0);
  FRAMEWIN_AddMaxButton(hWin, FRAMEWIN_BUTTON_RIGHT, 0);
  FRAMEWIN_AddMinButton(hWin, FRAMEWIN_BUTTON_RIGHT,0);
  
  
  return hWin;
}

// USER START (Optionally insert additional public code)
// USER END

/*************************** End of file ****************************/
